/**
 * Date:2021年4月29日 下午3:00:34
 * Copyright (c) 2021, www.bwbroad.com All Rights Reserved
 */

package com.app.common.config;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Description: mq 消息序列化配置 <br/>
 * Date:2021年4月29日 下午3:00:34 <br/>
 * 
 * @author xuejianxin
 */
@Configuration
public class RabbitMQConfig {

	@Autowired
	ObjectMapper jacksonObjectMapper;

	// mq消息转换
	// @Bean
	// public MessageConverter rabbitMQJsonMessageConverter() {
	// return new Jackson2JsonMessageConverter(jacksonObjectMapper);
	// }

	@Bean
	public SimpleRabbitListenerContainerFactory  rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
		var factory = new SimpleRabbitListenerContainerFactory();
		factory.setConnectionFactory(connectionFactory);
		factory.setMessageConverter(new Jackson2JsonMessageConverter(jacksonObjectMapper));
		factory.setAdviceChain(null);
		//var container = factory.createListenerContainer();
		// 配置重试
		//container.setAdviceChain(null);
		return factory;
	}

}